;SLIDE Float Library 

 INCLUDE "libraries.inc"

 CreateLibrary Float,FLoad,FLargeNum,FSmallNum,FPlus,FMinus,FMult,FDiv,FInc,FDec,FIPart,FFPart,FSqRoot,FIfEqu,FIfNEqu,FIfGreater,FIfLess,FSquare,FRand,FToVar

 CreateExp Float1
 CreateExp Float2
 CreateExp Float3
 CreateExp Float4
 CreateExp Float5
 CreateExp Float6
 CreateExp Float7
 CreateExp Float8
LastFloat EQU Float8+1
 RAMVar _Float1,float
 RAMVar _Float2,float
 RAMVar _Float3,float
 RAMVar _Float4,float
 RAMVar _Float5,float
 RAMVar _Float6,float
 RAMVar _Float7,float
 RAMVar _Float8,float
 RAMVar CurrentOP,2
 PUBLIC Float1,Float2,Float3,Float4,Float5,Float6,LastFloat,Float7,Float8

 IFDEF __FToVar
_FToVar_:
       call   FLdHLIndToOP1
       B_CALL LdHLInd
       push   hl
       B_CALL ConvOP1
       pop    hl
       ex     de,hl
       jp     LoadToVar
 ENDIF

 IFDEF __FIfEqu
_FIfEqu_:
       call   FLdHLIndToOP1
       call   FLdHLIndToOP2
       B_CALL CpOP1OP2
       ret    z
       jp     SkipNextCmdRet
 ENDIF

 IFDEF __FIfNEqu
_FIfNEqu_:
       call   FLdHLIndToOP1
       call   FLdHLIndToOP2
       B_CALL CpOP1OP2
       ret    nz
       jp     SkipNextCmdRet
 ENDIF

 IFDEF __FIfGreater
_FIfGreater_:
       call   FLdHLIndToOP1
       call   FLdHLIndToOP2
       B_CALL CpOP1OP2
       jp     z,SkipNextCmdRet
       ret    nc
       jp     SkipNextCmdRet
 ENDIF

 IFDEF __FIfLess
_FIfLess_:
       call   FLdHLIndToOP1
       call   FLdHLIndToOP2
       B_CALL CpOP1OP2
       ret    c
       jp     SkipNextCmdRet 
 ENDIF

 IFDEF __FRand
_FRand_:
       call   FLdHLIndToOP1
       B_CALL LdHLInd
       push   hl
       B_CALL PushRealO1
       B_CALL Random
       B_CALL PopRealO2
       B_CALL FPMult
       jp     PopHLFLoadToVar
 ENDIF

 IFDEF __FSquare
_FSquare_:
       B_CALL LdHLInd
       push   hl
       call   FLdHLToOP1
       B_CALL FPSquare
       jp     PopHLFLoadToVar
 ENDIF

 IFDEF __FSqRoot
_FSqRoot_:
       B_CALL LdHLInd
       push   hl
       call   FLdHLToOP1
       B_CALL SqRoot
       jp     PopHLFLoadToVar
 ENDIF

 IFDEF __FPlus
_FPlus_:
       call   FLdHLIndToOP1
       call   FLdHLIndToOP2
       B_CALL LdHLInd
       push   hl
       B_CALL FPAdd
       jp     PopHLFLoadToVar
 ENDIF

 IFDEF __FMinus
_FMinus_:
       call   FLdHLIndToOP1
       call   FLdHLIndToOP2
       B_CALL LdHLInd
       push   hl
       B_CALL FPSub
       jp     PopHLFLoadToVar
 ENDIF

 IFDEF __FMult
_FMult_:
       call   FLdHLIndToOP1
       call   FLdHLIndToOP2
       B_CALL LdHLInd
       push   hl
       B_CALL FPMult
       jp     PopHLFLoadToVar
 ENDIF

 IFDEF __FDiv
_FDiv_:
       call   FLdHLIndToOP1
       call   FLdHLIndToOP2
       B_CALL LdHLInd
       push   hl
       B_CALL FPDiv
       jp     PopHLFLoadToVar
 ENDIF

 IFDEF __FIPart
_FIPart_:
       B_CALL LdHLInd
       push   hl
       call   FLdHLToOP1
       B_CALL Trunc
       jp     PopHLFLoadToVar
 ENDIF

 IFDEF _FFPart
_FFPart_:
       B_CALL LdHLInd
       push   hl
       call   FLdHLToOP1
       B_CALL Frac
       jp     PopHLFLoadToVar
 ENDIF

 IFDEF __FInc
_FInc_:
       B_CALL LdHLInd
       push   hl
       call   FLdHLToOP1
       B_CALL Plus1
       jp     PopHLFLoadToVar
 ENDIF

 IFDEF __FDec
_FDec_:
       B_CALL LdHLInd
       push   hl
       call   FLdHLToOP1
       B_CALL Minus1
       jp     PopHLFLoadToVar
 ENDIF

 IFDEF __FLoad
_FLoad_:
       ld     e,(hl)
       inc    hl
       ld     d,(hl)        ;DE = load to
       inc    hl
       B_CALL LdHLInd       ;HL = load from
       push   de
       push   hl
       ld     bc,Float1
       or     a
       sbc    hl,bc
       ld     bc,LastFloat-Float1
       scf
       sbc    hl,bc
       pop    hl
       jr     c,FLoadVar
       B_CALL SetXXXXOP2
       B_CALL OP2ToOP1
       jp     PopHLFLoadToVar
FLoadVar:
       call   FLdHLToOP1
       jp     PopHLFLoadToVar
 ENDIF

 IFDEF __FLargeNum
 IFNDEF __FSmallNum
 DEFINE __FSmallNum
_FSmallNum EQU 0
 ENDIF
_FLargeNum_:
       set    fracDrawLFont,(iy+fontFlags)
 ENDIF

 IFDEF __FSmallNum
_FSmallNum_:
       call   LoadCoords
       call   FLdHLIndToOP1
       ld     a,7
       call   SaveTextStuff
       set    textWrite,(iy+sGrFlags)
       B_CALL DispOP1A
       call   RestoreTextStuff
       res    textWrite,(iy+sGrFlags)
       B_CALL DispOP1A
       res    fracDrawLFont,(iy+fontFlags)
       ret
 ENDIF


FLdHLIndToOP2:
       push   hl
       B_CALL LdHLInd
;       jr     FLdHLToOP2Cont
;FLdHLToOP2:
;       push   hl
;FLdHLToOP2Cont:
       ld     de,OP2
       ld     (CurrentOP),de
       jr     FLdHLToOPXCont

FLdHLIndToOP1:
       push   hl
       B_CALL LdHLInd
       jr     FLdHLToOP1Cont
FLdHLToOP1:
       push   hl
FLdHLToOP1Cont:
       ld     de,OP1
       ld     (CurrentOP),de
FLdHLToOPXCont:
       ld     de,Float1
       or     a
       sbc    hl,de
       jr     c,FLdHLToOPXNoOP
       B_CALL HLTimes9
       ld     de,_Float1
       add    hl,de
FLdHLToOPXCont2:
       ld     de,(CurrentOP)
       B_CALL Mov9B
       pop    hl
       inc    hl
       inc    hl
       ret
FLdHLToOPXNoOP:
       add    hl,de
       push   hl
       ld     de,VarA
       or     a
       sbc    hl,de
       ex     de,hl
       pop    hl
       jr     c,FLdHLToOPXNoVar
       ex     de,hl
       add    hl,hl
       ld     de,Variables
       add    hl,de
       B_CALL LdHLInd
FLdHLToOPXNoVar:
       push   hl
       B_CALL PushRealO2
       pop    hl
       B_CALL SetXXXXOP2
       B_CALL OP2ToOP6
       B_CALL PopRealO2
       ld     hl,OP6
       jr     FLdHLToOPXCont2


PopHLFLoadToVar:
       pop    hl
FLoadToVar:
                                   ;Load OP1 to float variable in hl
       ld     de,Float1
       or     a
       sbc    hl,de
       B_CALL HLTimes9
       ld     de,_Float1
       add    hl,de
       ex     de,hl
       B_CALL MovFrOP1
       ret

FloatNext:
 IFDEF _S_FLoad
       db     6
 ENDIF
 IFDEF _S_FLargeNum
       db     6
 ENDIF
 IFDEF _S_FSmallNum
       db     6
 ENDIF
 IFDEF _S_FPlus
       db     8
 ENDIF
 IFDEF _S_FMinus
       db     8
 ENDIF
 IFDEF _S_FMult
       db     8
 ENDIF
 IFDEF _S_FDiv
       db     8
 ENDIF
 IFDEF _S_FInc
       db     4
 ENDIF
 IFDEF _S_FDec
       db     4
 ENDIF
 IFDEF _S_FFPart
       db     4
 ENDIF
 IFDEF _S_FIPart
       db     4
 ENDIF
 IFDEF _S_FSqRoot
       db     4
 ENDIF
 IFDEF _S_FIfEqu
       db     6
 ENDIF
 IFDEF _S_FIfNEqu
       db     6
 ENDIF
 IFDEF _S_FIfGreater
       db     6
 ENDIF
 IFDEF _S_FIfLess
       db     6
 ENDIF
 IFDEF _S_FSquare
       db     4
 ENDIF
 IFDEF _S_FRand
       db     6
 ENDIF      
 IFDEF _S_FToVar
       db     6
 ENDIF



 PUBLIC _Float1,_FLoad_
